$(function () {
    var lift_gps_address = $("#tyibs_lift_gps_address").val();
    var has_lift = $("#tyibs_lift_id").val();
    var lift_icon = new BMap.Icon("/er/static/src/img/warning.gif",new BMap.Size(80,80));
    var map = new BMap.Map("tyibs-save-map");
    map.enableScrollWheelZoom(true);
    if (has_lift != ''){
        //有电梯，设置电梯的marker
        if (lift_gps_address == ""){
            // 没有GPS地址
            set_marker($("#tyibs_lift_lng").val(), $("#tyibs_lift_lat").val());
        }else {
            //有GPS地址
            $.ajax({
                url:"http://api.map.baidu.com/geocoder/v2/?address=无锡市" + lift_gps_address +"&output=json&ak=XYeVsCzcw7Rz0cCt3ZnZtBD2ohUTlMXX&callback=showLocation",
                dataType:'jsonp',
                data:'',
                jsonp:'callback',
                success:function(gps_result) {
                    set_marker(gps_result.result.location.lng, gps_result.result.location.lat);
                },
                error:function(){
                    alert("无法获取到位置。")
                }
            });
        }
    }
    else {
        //没有电梯，设置为中心
        map.centerAndZoom("无锡市", 12);
    }
    function set_marker(lng, lat) {
        //设置电梯的maker
        var point = new BMap.Point(lng, lat);
        var marker = new BMap.Marker(point, {icon: lift_icon});

        marker.addEventListener('click', function () {
            var info_window = new BMap.InfoWindow($(".tyibs-map-info-window-hidden").html());
            map.openInfoWindow(info_window,point);
        });
        map.centerAndZoom(point, 15);
        map.addOverlay(marker);
    }

});